package com.example.shopp_2301.search

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.GoodsEntity
import com.example.base.mvvm.BaseModel
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class SearchViewModel:BaseViewModel() {
    //返回值--搜索
    val searchSuccess = MutableLiveData<BaseModel<GoodsEntity>>()
    val searchFail = MutableLiveData<String>()
    fun search(keyword:String,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                searchSuccess.value = apiServer.search(keyword, limit, page)
            }catch (e:Exception){
                searchFail.value = e.message
            }
        }
    }
}